package com.hualan.zhsq.service.impl.car;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hualan.zhsq.entity.car.MonthlyCard;
import com.hualan.zhsq.mapper.car.MonthlyCardMapper;
import com.hualan.zhsq.service.car.MonthlyCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName MonthlyCardServiceImpl
 * @Description TODO
 * @Author ZheRan
 * @Date 2025年08月07日 下午4:05
 * @Version 1.0
 */
@Service("monthlyCardService")
public class MonthlyCardServiceImpl implements MonthlyCardService {

    @Autowired
    private MonthlyCardMapper monthlyCardMapper;

    @Override
    public Map<String, Object> monthlyCardResident(Integer pageNum, Integer pageSize, MonthlyCard entity) {
            Page<MonthlyCard> page = new Page<>(pageNum, pageSize);
            Page<MonthlyCard> monthlyCardPage = monthlyCardMapper.selectAllPage(page, entity);

            long size=monthlyCardPage.getSize();
            long total=monthlyCardPage.getTotal();
            List<MonthlyCard> list=monthlyCardPage.getRecords();

            Map<String, Object> map = new HashMap<>();
            map.put("total", total);
            map.put("size", size);
            map.put("list", list);
            return map;
    }


    @Override
    public int add(MonthlyCard entity) {
        return monthlyCardMapper.insert(entity);
    }

    @Override
    public int edit(MonthlyCard entity) {
        return monthlyCardMapper.updateById(entity);
    }

    @Override
    public int remove(Integer id) {
        return monthlyCardMapper.deleteById(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return monthlyCardMapper.deleteBatchIds(List.of(ids));
    }

    @Override
    public List<MonthlyCard> find() {
        return monthlyCardMapper.selectList(null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, MonthlyCard entity) {
        Page<MonthlyCard> page = new Page<>(pageNum, pageSize);
        Page<MonthlyCard> monthlyCardPage = monthlyCardMapper.selectPage(page, null);
        Map<String, Object> map = new HashMap<>();
        long size=monthlyCardPage.getSize();
        long total=monthlyCardPage.getTotal();
        List<MonthlyCard> list=monthlyCardPage.getRecords();
        map.put("total", total);
        map.put("size", size);
        map.put("list", list);
        return map;
    }

    @Override
    public MonthlyCard findById(Integer id) {
        return monthlyCardMapper.selectById(id);
    }
}
